package fr.jgraph.model.edge;

import java.util.Arrays;
import java.util.HashSet;

import fr.jgraph.model.vertex.Vertex;

public class ConcreteEdge implements Edge{
	private Object content;

	private Vertex[] vertexSet;
	
	protected ConcreteEdge(Object obj, Vertex[] v) {
		if (v.length < 2)
			throw new IllegalArgumentException(
					"Trying to create an edge linking less than 2 vertices.");
		setContent(obj);
		setVertexSet(v);
	}
	
	public void setVertexSet(Vertex[] v) {
		vertexSet = v;
	}
	
	public Object getContent() {
		return content;
	}

	public void setContent(Object object) {
		content = object;
	}

	public Vertex[] vertexSet() {
		return vertexSet;
	}
	
	public boolean equals(Object obj) {
		if (obj instanceof Edge) {
			Edge edge = (Edge) obj;

			HashSet set1 = new HashSet(Arrays.asList(vertexSet));
			HashSet set2 = new HashSet(Arrays.asList(edge.vertexSet()));

			return getContent().equals(edge.getContent()) && set1.equals(set2);
		}
		return false;
	}
}
